﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Interfaces;
using Core.Interfaces.IDAO;
using Core.Interfaces.IPresenters;
using Core.Unity;
using Microsoft.Practices.Unity;
namespace Core.Presenters
{
    class PrivatePersonPresenter
    {
        private IPrivatePersonDAO _privatePersonDAO;
        private IPrivatePerson _privatePerson;
        private IPrivatePersonView _view;

        public PrivatePersonPresenter(IPrivatePersonView view, IPrivatePerson privatePerson = null )
        {
            _privatePerson = privatePerson ?? ResolverContainer.Resolver.Resolve<IPrivatePerson>();
            
            _privatePersonDAO = ResolverContainer.Resolver.Resolve<IPrivatePersonDAO>(); 
            _view = view;
            _view.PrivatePirson.DataSource = _privatePerson;
            _view.SaveCustomer += SavePrivatePirson;
            view.ShowDialog();
        }



        private void SavePrivatePirson(object sender,EventArgs eventArgs)
        {
            
            _privatePersonDAO.SaveOrUpdateAndCommit((IDomainObject) _view.PrivatePirson.Current);
        }
    }
}
